package day06;

import java.io.File;
import java.util.Arrays;

/**
 * 获取并输出当前目录下的所有文件和目录的名字
 * @author Bonnie
 *
 */
public class Test04 {
    public static void main(String[] args) {
        File file = new File("./Home_Work/src/day06");
        listAllFiles(file, 0);
    }

    public static void listAllFiles(File file, int depth) {
        System.out.println(getIndent(depth) + file.getName());
        if (file.isDirectory()) {
            File[] items = file.listFiles();
            for (File item : items) {
                listAllFiles(item, depth + 1);
            }
        }
    }

    public static String getIndent(int depth) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < depth; i++) {
            sb.append(" ");
        }
        return sb.toString();
    }

}
